package com.limao.CacheManager;

import com.Hazelcast.Cache;
import com.Hazelcast.CacheFactory;
import com.limao.DBDataClass.CrowdPrestigeParmDataClass;
import com.limao.DBProvider.CrowdPrestigeParmProvider;
import com.limao.cache.BasicModule;

public class CrowdPrestigeParmCache extends BasicModule{

	private CrowdPrestigeParmProvider provider;
	private static CrowdPrestigeParmCache instance;

	public static CrowdPrestigeParmCache getInstance() {
		return instance;
	}

	private Cache<String, CrowdPrestigeParmDataClass> Order_PrestigeParmCache;

	public CrowdPrestigeParmCache() {
    	super("CrowdPrestigeParmCache");
    	Order_PrestigeParmCache = CacheFactory.createCache("crowd_PrestigeParmCache");
		initProvider();
	}
    
    @Override
	public void initialize() {
        super.initialize();
        instance=this;
    }
	
    public void ClearObjectCache()
    {
    	Order_PrestigeParmCache.clear();

    }  
    
    public void ClearObjectCache(String type)
    {
    	CrowdPrestigeParmDataClass tmp = Order_PrestigeParmCache.get(type);
    	if(tmp!=null)
    		Order_PrestigeParmCache.remove(type);

    } 
    
 	
  	
  	public CrowdPrestigeParmDataClass Load_CrowdPrestigeParm(int type,int level)
    {
  		if(type!=1)  //购物
  		{
  			level=0;
  		}
  		CrowdPrestigeParmDataClass tmp=Order_PrestigeParmCache.get(type+"_"+level);
  		if(tmp==null)
  		{
  			tmp=provider.Load_CrowdPrestigeParm(type,level);
  			if(tmp!=null)
  			{
  				Order_PrestigeParmCache.put(type+"_"+level, tmp);
  			}
  		}
  		
     	return tmp;
    }
  	
  //**************************************************************************************************/	
  	private void initProvider() {
  		if (provider == null) {
  			try {
  				provider = CrowdPrestigeParmProvider.getInstance();
  			} catch (Exception e) {
  				e.printStackTrace();
  			}
  		}
  	}
  
}
